package xpn.platform.modules.workflow.definition.state;

import org.apache.shiro.authz.annotation.RequiresPermissions;

import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import org.springframework.data.rest.core.config.Projection;
import xpn.platform.common.repository.XpnRepository;
import xpn.platform.modules.workflow.definition.process.Process;

import java.util.List;


@RepositoryRestResource(path = "workflow_definition_states", excerptProjection = StateDefaultProjection.class)
@SuppressWarnings("unchecked")
public interface StateDAO extends XpnRepository<State, Long> {
	/**
     * 根据名称精确匹配第一条记录  2017-12-29
     *
     * @param name
     * @return
     */
	State findFirstByName(String name);

    /**
     * 根据流程定义查询状态信息
     *
     * @param process
     * @return
     */
    List<State> findByProcess(Process process);

    /*
     * 保存权限控制
     */
    @RequiresPermissions("workflow.admin")
    @Override
    State save(State entity);

    /*
     * 删除权限控制
     */
    @RequiresPermissions("workflow.admin")
    @Override
    void delete(State entity);
}

/**
 * 缺省投影
 *
 * @author duwei
 */
@Projection(name = "default", types = {State.class})
interface StateDefaultProjection {

    Long getId();

    String getName();

    String getSortNo();

    String getDescription();

    String getTimeLimit();
}
